# Read Data
income <- read_csv ("data/income.csv" )
# Recode final class label for line break
income <- income |>
mutate (
Class = recode (Class, "$1000 AND OVER" = "1000 \n AND OVER" )
)
# left table
label_table <- income |>
mutate (
Class = factor (Class, levels = rev (c (
"$100-200" , "$200-300" , "$300-400" , "$400-500" ,
"$500-750" , "$750-1000" , "1000 \n AND OVER"
))),
row = as.numeric (Class)
) |>
ggplot (aes (y = Class)) +
geom_tile (aes (x = 1.5 , width = 2 , height = 1 ), fill = NA , color = "black" ) +
geom_segment (
data = tibble (y = seq (0.5 , 7.5 , 1 )),
aes (x = 0.9 , xend = 2.9 , y = y, yend = y),
inherit.aes = FALSE ,
color = "gray7" , linewidth = 0.2
) +
geom_segment (
data = tibble (x = c (0.9 , 1.95 , 2.9 )),
aes (x = x, xend = x, y = 0.5 , yend = 7.5 ),
inherit.aes = FALSE ,
color = "gray7" , linewidth = 0.2
) +
geom_text (aes (x = 1 , label = Class), hjust = 0 , size = 3.2 , fontface = "bold" , family = "mono" ) +
geom_text (aes (x = 2 , label = paste0 ("$" , Average_Income)), hjust = 0 , size = 3.2 , family = "mono" ) +
scale_y_discrete (limits = rev (c (
"$100-200" , "$200-300" , "$300-400" , "$400-500" ,
"$500-750" , "$750-1000" , "1000 \n AND OVER"
))) +
xlim (0.9 , 2.9 ) +
labs (title = NULL , x = NULL , y = NULL ) +
theme_void () +
theme (
plot.margin = margin (5 , 0 , 5 , 5 ),
axis.text.y = element_blank (),
plot.background = element_rect (fill = NA , color = NA ),
panel.background = element_rect (fill = NA , color = NA )
)
data <- income |>
pivot_longer (cols = Rent: Other, names_to = "type" , values_to = "measurement" ) |>
mutate (
type = factor (type, levels = c ("Rent" , "Food" , "Clothes" , "Tax" , "Other" )),
Class = factor (Class, levels = rev (c (
"$100-200" , "$200-300" , "$300-400" , "$400-500" ,
"$500-750" , "$750-1000" , "1000 \n AND OVER"
)))
)
data$ measurement[data$ measurement == 0 ] <- 0.1
category <- c (
Rent = "#000000" ,
Food = "#8663A3" ,
Clothes = "#E89A8D" ,
Tax = "slategray3" ,
Other = "#D6C8B0"
)
bar_plot <- ggplot (data, aes (x = Class, y = measurement, fill = type)) +
geom_bar (stat = "identity" , width = 0.8 ) +
geom_text (
aes (label = ifelse (measurement >= 1 , paste0 (measurement, "%" ), "" )),
position = position_stack (vjust = 0.5 ),
size = 3 ,
color = "white"
) +
scale_y_reverse () +
scale_fill_manual (values = category) +
coord_flip () +
labs (
x = NULL ,
y = NULL ,
subtitle = "FOR FURTHER STATISTICS RAISE THIS FRAME."
) +
theme_minimal (base_size = 12 ) +
theme (
plot.title = element_text (face = "bold" , hjust = 0 , size = 12 ),
axis.text.y = element_blank (),
axis.text.x = element_blank (),
axis.ticks.x = element_blank (),
panel.grid.major.y = element_blank (),
panel.grid.major.x = element_blank (),
legend.title = element_blank (),
legend.position = "top" ,
legend.direction = "horizontal" ,
legend.justification = "center" ,
plot.subtitle = element_text (
family = "fira" ,
face = "plain" ,
hjust = 0.5 ,
size = 10 ,
margin = margin (t = 10 )
)
)
combined_plot <- (label_table + bar_plot + plot_layout (widths = c (1.3 , 3 )))
final_plot <- ggbackground (combined_plot, "images/parchment_paper-1074131_1920.png" )
print (final_plot)